<?php
/**
 * Created by PhpStorm.
 * User: zhengrunqiang
 * Date: 2016-12-21
 * Time: 10:32
 */

class ModelAccountCustomerChild extends Model {
    public function addChild($data){
        $this->db->query("INSERT INTO " . DB_PREFIX . "customer_child SET name = '" . $this->db->escape($data['name']) . "', school = '" . $this->db->escape($data['school']) . "', customer_id = '".(int)$this->customer->getId()."', date_added = now(), birthday = '".$this->db->escape($data['birthday'])."',grade='".$this->db->escape($data['grade'])."',sort='".(int)$data['sort']."'");
    }

    public function updateChild($data){
        $this->db->query("UPDATE " . DB_PREFIX . "customer_child SET name = '".$this->db->escape($data['name'])."', birthday = '".$this->db->escape($data['birthday'])."' , school ='".$this->db->escape($data['school'])."',grade = '".$this->db->escape($data['grade'])."',customer_id = '".(int)$this->customer->getId()."'WHERE customer_id = '" . (int)$this->customer->getId() ."' and sort = '".(int)$data['sort']."' ");
    }

    public function getChildBySort($sort){
        $query = $this->db->query("SELECT  * FROM `" . DB_PREFIX . "customer_child` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'and sort = '".(int)$sort."'");

        return $query->row;
    }

    public function getCustomerChilds(){
        $query = $this->db->query("SELECT  * FROM `" . DB_PREFIX . "customer_child` WHERE `customer_id` = '" . (int)$this->customer->getId() . "'");
        return $query->rows;
    }
}